<?php
/**
 * Description of PesertaNonRutin
 *
 * @author Alvin Andhika
 */

    class PesertaNonRutin extends CI_Model
    {
        function PesertaNonRutin_model() {
                parent::Model();
        }

		public function add($activity_id, $user_id){
			if(is_array($user_id)){
				$sql = 'insert into pesertanonrutin (activityID, userID) values ';
				foreach($user_id as $id){
					$sql .= "($activity_id, '$id'),";
				}
				$sql = substr($sql, 0, -1);
			}
			else{
				$sql = "insert into pesertanonrutin (activityID, userID) values ($activity_id, '$user_id')";
			}
			$this->db->query($sql);
		}

		public function getPeserta($activity_id){
			$sql = "SELECT * from pengguna where userID in (select userID from pesertanonrutin where activityID  = $activity_id)";
			$query = $this->db->query($sql);
			if ($query->num_rows() > 0){
				$result = array();
				foreach($query->result_array() as $row){
					$result[] = $row;
				}
				return $result;
			 }
		}
    }
?>

